package com.wwu.schedule.config;

import cn.hutool.core.date.DateUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务管理器
 * @author 一蓑烟雨
 * @version 1.0.0
 * @date 2023-04-15 12:06
 **/
@Component
@Async
public class ScheduleManager {
    @Scheduled(cron = "0/20 * * * * ?")
    public void FirstJob() {
        System.out.println(DateUtil.date() +"--"+Thread.currentThread().getName()+"--第1个定时任务启动");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(DateUtil.date() +"--"+Thread.currentThread().getName()+"--第1个定时任务结束");
    }

    @Scheduled(cron = "0/20 * * * * ?")
    public void SecondJob() {
        System.out.println(DateUtil.date() +"--"+Thread.currentThread().getName()+"--第2个定时任务启动");
        try {
            Thread.sleep(8000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(DateUtil.date() +"--"+Thread.currentThread().getName()+"--第2个定时任务结束");
    }

}
